package io.renren.socket;

import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import io.renren.common.utils.StringUtils;
import io.renren.modules.substation.controller.TInfoBackupConfigController;
import org.msgpack.MessagePack;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 编码器
 * @author Administrator
 *
 */
public class MsgPckEncode extends MessageToByteEncoder<Object>{
    private static Logger logger = LoggerFactory.getLogger(TInfoBackupConfigController.class);

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf buf)
            throws Exception {
        // TODO Auto-generated method stub
        MessagePack pack = new MessagePack();

//        String hexStr = StringUtils.stringToHexString(msg.toString());
        byte[] write = StringUtils.hexStringToByteArray(msg.toString());
//        byte[] write = pack.write(hexStr);

        buf.writeBytes(write);
        logger.debug("已发出数据:" + msg);
        buf = Unpooled.copiedBuffer(msg.toString(), CharsetUtil.UTF_8);
    }




}
